package cn.myjava.gupao.mode.prototype;

import org.springframework.beans.BeanUtils;

/**
 * 原型模式
 * Created by RenFu
 * Date: 2019/5/16
 */
public class UtilsTest {

    public static void main(String[] args) {
        Student1 student1 = new Student1();
        student1.setCode("001");
        student1.setName("张三");
        student1.setSex("男");
        student1.setAge(25);
        student1.setClassId(1);
        Student2 student2 = new Student2();
        BeanUtils.copyProperties(student1, student2);
        System.out.println(student2.toString());

        StudentOne studentOne = new StudentOne();
        studentOne.setCode("001");
        studentOne.setName("张三");
        studentOne.setSex("男");
        studentOne.setAge(25);
        studentOne.setClassId(1);
//        Client client = new Client(studentOne);
        Client client = new Client();
        StudentOne s2 = (StudentOne) client.startClone(studentOne);
        System.out.println(s2.toString());

        try {
            StudentHistoryBook studentHistoryBook = new StudentHistoryBook();
//            studentHistoryBook.setName("张三");
            StudentHistoryBook clone = (StudentHistoryBook) studentHistoryBook.clone();
            System.out.println("深克隆：" + (studentHistoryBook.historyBook == clone.historyBook));
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
    }

}
